<?php
namespace app\wxapp\controller;
//use app\common\controller\Base;

class Wx extends Base{



	public function getopenid( $jscode = null ){
		if(!$jscode){ return 0 ;}

		// $this->t();


		$JSCODE = $jscode;
		$APPID = config('wx_appid');
		$SECRET = config('wx_appsecret');
		$url = 'https://api.weixin.qq.com/sns/jscode2session?appid=APPID&secret=SECRET&js_code=JSCODE&grant_type=authorization_code';
		$url = str_replace( ['APPID','SECRET','JSCODE'] , [$APPID,$SECRET,$JSCODE] , $url );
		$rs = httpGet($url);
		$rs = $rss = json_decode($rs,true);

		if(isset($rs['errcode'])){
			$this->res['msg'] = '请求错误！';
			$this->res['data'] = $rs;
			die(myJSON($this->res));
		}


		// $openid = $rs['openid'];
		// $session_key = $rs['session_key'];

		$this->res['data'] = $rs;

		die(myJSON($this->res));
	}


	public function sentmsg(){
		$formid = input('formid');

		$access_token = '8_wpHf3N95MsG5Ayvz_VDSIZ0VtSJpctKZGSwbD8rENQVTEdZGISAr1xny-o3YIu1ln_cmbV9xMF2sWRlWRXgHFtwXYlE7LMv7JS2HuGZE5HvWYQ-G88m8lgWrIGMXNOW8fEZtSGoAxvzdOhtOWKUjAGAQEO';
		$url = 'https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=' . $access_token;

		$openid = 'ozPAh0Uk27nZZYUIbqt-SgYHa9EU';

		$data = array();
		$data['touser'] = $openid;
		$data['template_id'] = '9qnH6do9fbQZDlNMqlmOyPuUjtVhVlLnl3AO-TE55rI';
		$data['page'] = 'pages/index/index';
		$data['form_id'] = $formid;
		$data['data'] = '';


		$rs = httpPost($url,$data);
		die($rs);
	}

}